package com.xunqi.ware.service.impl;

import com.xunqi.ware.entity.PurchaseEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xunqi.common.utils.PageUtils;
import com.xunqi.common.utils.Query;

import com.xunqi.ware.dao.PurchaseDetailDao;
import com.xunqi.ware.entity.PurchaseDetailEntity;
import com.xunqi.ware.service.PurchaseDetailService;


@Service("purchaseDetailService")
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailDao, PurchaseDetailEntity> implements PurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<PurchaseDetailEntity> wrapper = new QueryWrapper<>();

        String key = params.get("key")==null?"":params.get("key").toString();
        if (!StringUtils.isEmpty(key)){
            wrapper.eq("id",key).or().like("purchase_id",key)
                    .or().like("sku_id",key).or().like("sku_num",key)
                    .or().like("sku_price",key);
        }
        String status = params.get("status").toString();
        if (!StringUtils.isEmpty(status)){
            wrapper.eq("status",status);
        }
        String wareId = params.get("wareId").toString();
        if (!StringUtils.isEmpty(wareId)){
            wrapper.eq("ware_id",wareId);
        }

        IPage<PurchaseDetailEntity> page = this.page(
                new Query<PurchaseDetailEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<PurchaseDetailEntity> listDetailBy(PurchaseEntity item) {
        List<PurchaseDetailEntity> purchase_id = this.list(new QueryWrapper<PurchaseDetailEntity>().eq("purchase_id", item.getId()));

        return purchase_id;
    }

}